package com.longge;

import java.util.ArrayList;
import java.util.List;

public class BinaryTreePaths {

    List<String> res = new ArrayList<>();

    public List<String> binaryTreePaths(TreeNode root) {
        dfs(root, "");
        return res;
    }

    private void dfs(TreeNode root, String s) {
        if (root == null) {
            return;
        }

        if (!s.equals("")) {
            s += "->" + root.val;
        } else s += root.val;
        if (root.left==null&&root.right==null){
            res.add(s);
        }
        dfs(root.left, s);
        dfs(root.right, s);
    }
}
